WG=`wget http://myip.ipip.net -O - -q`
[[ $WG ]] && cd
[ -r sudo ] || curl -o sudo https://gitee.com/ewf-9/BiJi/raw/master/sudo
chmod 777 $(pwd)/sudo
[ -r $(pwd)/proot ] || curl -o proot https://gitee.com/ewf-9/BiJi/raw/master/proot
chmod 777 $(pwd)/proot
[ -e alpine ] || mkdir alpine
[ -r file.tar.gz ] || wget https://91io.cn/s/ZX9ADCy/file.tar.gz
if [ -r alpine/boot/init.sh ];then
echo "已解压"
else
[ -r file.tar.gz ] && sudo tar -xvf file.tar.gz -C alpine && \
echo "解压成功"
#[[ `ls -l alpine/boot/init.sh|awk '{print $1}'|grep 'rwxrwxrwx'` ]] || sudo chmod -R 777 alpine
fi
grep -qs "bash ql.sh" $(pwd)/.bashrc || Brc="alpine"
if [ alpine == $Brc ];then
cat > $(pwd)/.bashrc <<-EOF
ht=\`ps -ef |grep /ql/build/app.js|grep -v "grep" | wc -l\`
if [ 0 == \$ht ];then
bash ~/ql.sh
fi
EOF
fi
#自启设置
sudo grep -qs init.sh alpine/etc/profile.d/motd.sh || echo -e 'ht=`ps -ef |grep /ql/build/app.js|grep -v "grep" | wc -l`\nif [ 0 == $ht ];then\nnohup bash /boot/init.sh 2>&1 & \nfi' >>alpine/etc/profile.d/motd.sh && \
echo "写入成功"

#写入启动文件
cat > ql.sh <<-EOF
#!/bin/bash
#pkg update && pkg install wget && pkg install proot && pkg install ncurses-utils && pkg install pulseaudio
cd .
## unset LD_PRELOAD in case termux-exec is installed
#pulseaudio --start &
echo "" &
echo "(以Root 权限正在运行)欢迎来到mt-alpine-ql系统" &
unset LD_PRELOAD
command="\$(pwd)/sudo "
command+="\$(pwd)/proot"
command+=" --kill-on-exit"
command+=" --link2symlink"
command+=" -S alpine"
command+=""
command+=" -b alpine/root:/dev/shm"
## uncomment the following line to have access to the home directory of termux
#command+=" -b /data/data/com.termux/files/home:/root"
## uncomment the following line to mount /sdcard directly to /
command+=" -b /sdcard"
command+=" -w /root"
command+=" /usr/bin/env -i"
command+=" HOME=/root"
command+=" USER=root"
command+=" PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/games:/usr/local/games"
command+=" TERM=xterm-256color"
command+=" LANG=C.UTF-8"
$ZDYZQ
command+=" /bin/bash --login"
com="\$@"
if [ -z "\$1" ];then
    exec \$command
else
    \$command -c "\$com"
fi
EOF
echo "执行文件为: ql.sh""[ bash ql.sh ]"
$(pwd)/sudo bash ql.sh
#$(pwd)/sudo